﻿using AutoMapper;
using Pay.Core;
using Pay.Data;
using Pay.DTO;
using Pay.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pay.Service.AutoMapper {
   
    public class TokenBazaarProductMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public TokenBazaarProductMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<TokenBazaarProduct, token_bazaar_product_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.product_name, src => src.MapFrom(c => c.ProductName))
                .ForMember(dest => dest.prodcut_desc, src => src.MapFrom(c => c.ProdcutDesc))
                .ForMember(dest => dest.market_price, src => src.MapFrom(c => c.MarketPrice))
                .ForMember(dest => dest.imgs, src => src.MapFrom(c => c.Imgs.ToObject<List<string>>()))
                .ForMember(dest => dest.main_img, src => src.MapFrom(c => c.MainImg))
                .ForMember(dest => dest.merchant_id, src => src.MapFrom(c =>c.MerchantId))
                .ForMember(dest => dest.merchant_name, src => src.MapFrom(c => c.Merchant.Name))
                  .ForMember(dest => dest.merchant_mobile, src => src.MapFrom(c => c.Merchant.Mobile))
                .ForMember(dest => dest.merchant_photo, src => src.MapFrom(c => c.Merchant.Photo))
                .ForMember(dest => dest.is_recommend, src => src.MapFrom(c => c.IsRecommend))
                .ForMember(dest => dest.num, src => src.MapFrom(c => c.Num))
                .ForMember(dest => dest.is_del, src => src.MapFrom(c => c.IsDel))
                .ForMember(dest => dest.status, src => src.MapFrom(c => c.Status))
                .ForMember(dest => dest.status_desc, src => src.MapFrom(c => c.Status.ToDescription()))
                .ForMember(dest => dest.category_id, src => src.MapFrom(c => c.CategoryId))
                 .ForMember(dest => dest.catagory_name, src => src.MapFrom(c => c.Category.Name))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                .ForMember(dest => dest.update_time, src => src.MapFrom(c => c.UpdateTime.ToDateTime()));



            _cfg.CreateMap<token_bazaar_product_base_dto, TokenBazaarProduct>()
               .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
               .ForMember(dest => dest.ProductName, src => src.MapFrom(c => c.product_name))
               .ForMember(dest => dest.ProdcutDesc, src => src.MapFrom(c => c.prodcut_desc))
               .ForMember(dest => dest.MarketPrice, src => src.MapFrom(c => c.market_price))
               .ForMember(dest => dest.Imgs, src => src.MapFrom(c => c.imgs.ToJson()))
               .ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
               .ForMember(dest => dest.CategoryId, src => src.MapFrom(c => c.category_id));
              


        }
    }
}
